// 漂流瓶相关API
import { post, get } from '../../common/httptools';
import { urlconstant } from '../../constant/index';

// 投放漂流瓶
export const throwBottle = async (data) => {
  try {
    const res = await post(urlconstant.BOTTLE.THROW_BOTTLE, data);
    return res;
  } catch (error) {
    console.error('投放漂流瓶失败', error);
    throw error;
  }
};

// 捞取漂流瓶
export const pickBottle = async () => {
  try {
    const res = await get(urlconstant.BOTTLE.PICK_BOTTLE);
    return res;
  } catch (error) {
    console.error('捞取漂流瓶失败', error);
    throw error;
  }
};

// 获取我的漂流瓶
export const getMyBottles = async (params = {}) => {
  try {
    const res = await get(urlconstant.BOTTLE.GET_MY_BOTTLES, params);
    return res;
  } catch (error) {
    console.error('获取我的漂流瓶失败', error);
    throw error;
  }
};

// 回复漂流瓶
export const respondBottle = async (data) => {
  try {
    const res = await post(urlconstant.BOTTLE.RESPOND_BOTTLE, data);
    return res;
  } catch (error) {
    console.error('回复漂流瓶失败', error);
    throw error;
  }
};

// 获取漂流瓶详情
export const getBottleDetail = async (params) => {
  try {
    const res = await get(urlconstant.BOTTLE.GET_BOTTLE_DETAIL, params);
    return res;
  } catch (error) {
    console.error('获取漂流瓶详情失败', error);
    throw error;
  }
};

// 点赞漂流瓶
export const likeBottle = async (data) => {
  try {
    const res = await post(`${urlconstant.BOTTLE.GET_BOTTLE_DETAIL}/like`, data);
    return res;
  } catch (error) {
    console.error('点赞漂流瓶失败', error);
    throw error;
  }
};

// 收藏漂流瓶
export const collectBottle = async (data) => {
  try {
    const res = await post(`${urlconstant.BOTTLE.GET_BOTTLE_DETAIL}/collect`, data);
    return res;
  } catch (error) {
    console.error('收藏漂流瓶失败', error);
    throw error;
  }
};

// 举报漂流瓶
export const reportBottle = async (data) => {
  try {
    const res = await post(`${urlconstant.BOTTLE.GET_BOTTLE_DETAIL}/report`, data);
    return res;
  } catch (error) {
    console.error('举报漂流瓶失败', error);
    throw error;
  }
};

// 获取漂流瓶统计数据
export const getBottleStats = async () => {
  try {
    const res = await get(`${urlconstant.BOTTLE.THROW_BOTTLE}/stats`);
    return res;
  } catch (error) {
    console.error('获取漂流瓶统计数据失败', error);
    throw error;
  }
};

export default {
  throwBottle,
  pickBottle,
  getMyBottles,
  respondBottle,
  getBottleDetail,
  likeBottle,
  collectBottle,
  reportBottle,
  getBottleStats
};